package com.ds.springboot.controller;

import com.ds.springboot.mapper.EmpMapper;
import com.ds.springboot.pojo.Employee;
import com.ds.springboot.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: springboot-1-cache
 * @description:
 * @author: Dawson.Zhang
 * @create: 2020-05-17
 **/
@RestController
public class EmpController {
    @Autowired
    EmpService empService;

    @GetMapping("/emp/{id}")
    public Employee getById(@PathVariable("id")Integer id){
        Employee byId = empService.getById(id);
        return byId;
    }
    @PostMapping("/emp")
    public Employee updateEmp(Employee employee){
        return empService.updateEmp(employee);
    }
    @DeleteMapping("/emp/{id}")
    public int  delEmp(@PathVariable("id") Integer id){
        int i = empService.delEmp(id);
        return i;

    }
    @PutMapping("/emp")
    public Employee addEmp(Employee employee){
        return empService.addMap(employee);
    }

    @GetMapping("lastname/{lastname}")
    public Employee getByLastName(@PathVariable("lastname") String lastName){
        Employee byLastName = empService.getByLastName(lastName);
        return byLastName;
    }
}
